package com.cyh.structurealgorithm;

import java.util.Arrays;

public class SelectSort {
    public static void test() {
        int arr[] = {3, 9, -1, 10, -2, 5, 10, 3, 11, -8, -2};
        for(int i = 0; i < arr.length - 1; i++) { //找出第几小的数据
            int minIndex = i;
            int min = arr[i];
            for(int j = i + 1; j < arr.length; j++) { //跟后面的数据比较，找出最小的
                if(min > arr[j]) {
                    min = arr[j];
                    minIndex = j;
                }
            }
            if(minIndex != i) {
                arr[minIndex] = arr[i];
                arr[i] = min;
            }
        }
        System.out.println(Arrays.toString(arr));
    }
}
